using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content.Pipeline.Serialization.Compiler;
using Phoenix.Xna.Framework.Graphics.Animation;

namespace Phoenix.Xna.Framework.ContentPipeline.Models
{
    public class SkinnedModelBoneContent
    {
        public string Name { get; private set; }
        public ushort Index { get; private set; }
        public SkinnedModelBoneContent Parent { get; internal set; }
        public SkinnedModelBoneContentCollection Children { get; internal set; }
        public Pose BindPose { get; private set; }
        public Matrix InverseBindPoseTransform { get; private set; }

        internal SkinnedModelBoneContent(ushort index, string name, Pose bindPose, Matrix inverseBindPoseTransform)
        {
            Index = index;
            Name = name;
            BindPose = bindPose;
            InverseBindPoseTransform = inverseBindPoseTransform;
        }

        internal void Write(ContentWriter output)
        {
            output.Write(Index);
            output.Write(Name);
            output.Write(BindPose.Translation);
            output.Write(BindPose.Orientation);
            output.Write(BindPose.Scale);
            output.Write(InverseBindPoseTransform);
            output.WriteSharedResource(Parent);
            output.Write(Children.Count);

            foreach (SkinnedModelBoneContent childBone in Children)
            {
                output.WriteSharedResource(childBone);
            }
        }
    }
}